﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CarbonMeter
{
    public partial class LoginForm : Form
    {
        private MyTabs myTabs;
        private LicenseEventArg arg;

        public LoginForm()
        {

            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        //giris butonu
        private void button1_Click(object sender, EventArgs e)
        {

            if (!Database.getInstance().DatabaseExists())
            {
                MessageBox.Show("Veri tabanına ulaşılamıyor!", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            int userid = 0;

            try
            {
                userid = int.Parse(maskedTextBox2.Text);
            }
            catch (Exception)
            {
             
            }
            String password = maskedTextBox1.Text;

            Database database = Database.getInstance();
            User user = database.verifyUser(userid, password);

            if (user == null)
            {
                MessageBox.Show("Yanlış Kullanıcı adı veya hatalı şifre..", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
              
                this.Hide();
                //Application.Run(new MainForm(user));    //NOT: Starting a second message loop on a single thread is not a valid operation. Use Form.ShowDialog instead.
                new MainForm(user,myTabs,arg).ShowDialog();
            }
        }

        internal void SetLicense(MyTabs myTabs, LicenseEventArg arg)
        {
            this.myTabs = myTabs;
            this.arg = arg;
        }
    }
}
